#ifndef _MONITOR_LOCK_H_
#define _MONITOR_LOCK_H_

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Threading;

class MonitorLock
{
public:
	MonitorLock(Object^ obj)
	{
		_ObjectHandle = GCHandle::Alloc(obj);
		Monitor::Enter(obj);
	}
	~MonitorLock()
	{
		Monitor::Exit(_ObjectHandle.Target);
		_ObjectHandle.Free();
	}
private:
	GCHandle _ObjectHandle;
};

#endif
